package OSdesign.GUI_show;

import OSdesign.Function_show.MySQL_Conn;
import OSdesign.Function_show.PlayerManager;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;

public class Menu_two extends JFrame {
    private JPanel reportPanel;
    private JTextField pnumField;
    private JTextField mnumField;
    private JTextField scoreField;
    private JTextField medalField;
    private JTextField totalField;
    public Object[][] objects;
    public Menu_two(){
        //构造函数
    }
    public JFrame getJFrame(){
        return this;
    }
    public void inputView(){
        String[] strs = new String[5];
        Font font = new Font("",Font.BOLD,20);
        reportPanel = new JPanel();
        reportPanel.setBounds(0,0,500,600);
        reportPanel.setLayout(null);

        JLabel pnumLabel = new JLabel("运动员编号");
        pnumLabel.setFont(font);
        pnumLabel.setBounds(50,50,200,50);
        JLabel mnumLabel = new JLabel("比赛编号");
        mnumLabel.setFont(font);
        mnumLabel.setBounds(50,120,200,50);
        JLabel scoreLabel = new JLabel("成绩");
        scoreLabel.setFont(font);
        scoreLabel.setBounds(50,190,200,50);
        JLabel medalLabel = new JLabel("获奖情况");
        medalLabel.setFont(font);
        medalLabel.setBounds(50,260,200,50);
        JLabel totalLabel = new JLabel("个人积分");
        totalLabel.setFont(font);
        totalLabel.setBounds(50,330,200,50);

        //文本框组件
        pnumField = new JTextField();
        pnumField.setFont(font);
        pnumField.setBounds(200,50,200,50);
        mnumField = new JTextField();
        mnumField.setFont(font);
        mnumField.setBounds(200,120,200,50);
        scoreField = new JTextField();
        scoreField.setFont(font);
        scoreField.setBounds(200,190,200,50);
        medalField = new JTextField();
        medalField.setFont(font);
        medalField.setBounds(200,260,200,50);
        totalField = new JTextField();
        totalField.setFont(font);
        totalField.setBounds(200,330,200,50);

        //确定添加按钮
        JButton button = new JButton("确定");
        button.setFont(font);
        button.setBounds(120,430,100,50);
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                strs[0] = pnumField.getText();
                strs[1] = mnumField.getText();
                strs[2] = scoreField.getText();
                strs[3] = medalField.getText();
                strs[4] = totalField.getText();
                if(new PlayerManager().addGrade(strs)){
                    JOptionPane.showMessageDialog(null,"录入成功！");
                    pnumField.setText("");
                    mnumField.setText("");
                    scoreField.setText("");
                    medalField.setText("");
                    totalField.setText("");
                }
            }
        });
        //添加返回按钮
        JButton unbutton = new JButton("返回");
        unbutton.setFont(font);
        unbutton.setBounds(270,430,100,50);
        unbutton.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                getJFrame().dispose();
            }
        });
        //组件添加到 panel 上
        reportPanel.add(pnumLabel);
        reportPanel.add(mnumLabel);
        reportPanel.add(scoreLabel);
        reportPanel.add(medalLabel);
        reportPanel.add(totalLabel);
        reportPanel.add(pnumField);
        reportPanel.add(mnumField);
        reportPanel.add(scoreField);
        reportPanel.add(medalField);
        reportPanel.add(totalField);
        reportPanel.add(button);
        reportPanel.add(unbutton);

        //panel添加到frame窗口
        this.setLayout(null);
        this.setBounds(600,250,500,600);
        this.setFocusable(false);
        this.add(reportPanel);
        this.setTitle("成绩录入");
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
/*
    public String rankView(){
        String[] strs = new String[4];
        Font font = new Font("",Font.BOLD,20);
        JPanel panel = new JPanel();
        panel.setBounds(0,0,500,600);
        panel.setLayout(null);

        JLabel nameLabel = new JLabel("输入比赛项目名称");
        nameLabel.setFont(font);
        nameLabel.setBounds(120,50,200,50);
        JTextField nameField = new JTextField();
        nameField.setFont(font);
        nameField.setBounds(120,130,250,50);
        //确定添加按钮
        JButton button = new JButton("确定");
        button.setFont(font);
        button.setBounds(120,230,100,50);
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                strs[0]=nameField.getText();
                getJFrame().dispose();

            }
        });
        //添加返回按钮
        JButton unbutton = new JButton("返回");
        unbutton.setFont(font);
        unbutton.setBounds(270,230,100,50);
        unbutton.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                getJFrame().dispose();
            }
        });

        //组件加入 panel
        panel.add(nameLabel);
        panel.add(nameField);
        panel.add(button);
        panel.add(unbutton);
        //panel添加到frame窗口
        this.setLayout(null);
        this.setBounds(600,250,500,400);
        this.setFocusable(false);
        this.add(panel);
        this.setTitle("名词判定");
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        System.out.println("字符串传入是否成功:"+strs[0]);

    }*/

    public static void main(String[] args){
    }
}
